package com.qd.flow.service.bill;

import com.cdqidi.exception.ApiException;
import com.qd.common.flow.domain.approval.ApprovalDTO;
import com.qd.common.flow.domain.bill.FlowBillDTO;
import com.qd.common.flow.domain.bill.FlowTaskDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author sjk
 * @create 2024-02-21 13:37
 * @since 1.0.0
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class FlowHolderService {
    private final FlowService flowService;
    private final FlowTaskService flowTaskService;
    private final FlowBillService flowBillService;

    public void approval(ApprovalDTO approvalDTO) {
        FlowTaskDTO flowTaskDTO = Optional.ofNullable(flowTaskService.getByIdDto(approvalDTO.getTaskId())).orElseThrow(() -> new ApiException("任务ID值错误"));
        FlowBillDTO flowBillDTO = flowBillService.getByIdDto(flowTaskDTO.getBillId());
        flowService.approval(approvalDTO, flowTaskDTO, flowBillDTO);
    }
}